package com.accesshollywood.grfxOrdering.basics;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedHashMap;

import javax.swing.DefaultComboBoxModel;

import com.accesshollywood.SQL.GFXSQL;
import com.accesshollywood.indexables.Destination;

public class Destinations {
	public static LinkedHashMap<Integer, Destination> allDestinations;
	public static DefaultComboBoxModel destinations;

	
	public static void populateDestinations() {
		allDestinations = new LinkedHashMap<Integer, Destination>();
		destinations = new DefaultComboBoxModel();

		try {
			ResultSet destResults = GFXSQL.getResultSet("destination", "*", "");
			while (destResults.next()) {
				Destination currDestination = new Destination();
				currDestination.fromSQL(destResults.getInt("idDestination"));
//				currDestination.idDestination = destResults.getInt("idDestination");
//				currDestination.name = destResults.getString("name");
				addDestinationToLists(currDestination);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}


	public static void addDestinationToLists(Destination newDestination) {
		allDestinations.put(newDestination.getId(), newDestination);
		if(destinations.getSize() > 0){
			destinations.insertElementAt(newDestination, destinations.getSize()-1);
		}else{
			destinations.addElement(newDestination);
		}
		//destinations.addElement(newDestination);
	}


	public static void addDestinationToSQL(Destination newDestination) {
		GFXSQL.addDestination(newDestination);
	}
}
